package com.muyu.danmo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.utils.PageUtils;
import com.muyu.danmo.service.EvaluationService;
import com.muyu.system.domain.Vo.CommentListVO;
import com.muyu.system.domain.Vo.EvaluationCountVO;
import com.muyu.system.domain.Vo.EvaluationListVO;
import com.muyu.system.domain.dto.CommentListDTO;
import com.muyu.system.domain.dto.CommentsDTO;
import com.muyu.system.domain.dto.EvaluationListDTO;
import com.muyu.system.domain.dto.ThumbsUpDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.muyu.common.core.domain.Result;

import javax.validation.Valid;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/evaluation")
@RequiredArgsConstructor
public class EvaluationController {

    private final EvaluationService evaluationService;


    /**
     * 获取商品的评价统计
     * @param goodId
     * @return
     */
    @GetMapping("/count/{goodId}")
    public Result<EvaluationCountVO> count(@PathVariable("goodId") Long goodId){
        return Result.success(evaluationService.count(goodId));
    }


    /**
     * 评价列表
     * @param evaluationListDTO
     * @return
     */
    @PostMapping("/list")
    public Result<PageInfo<EvaluationListVO>> list(@RequestBody @Valid EvaluationListDTO evaluationListDTO){
        IPage<EvaluationListVO> list = evaluationService.list(evaluationListDTO);
        return Result.success(PageUtils.convertToPageInfo(list));
    }


    /**
     * 发布评论
     * @param commentsDTO
     * @return
     */
    @PostMapping("/comments")
    public Result<String> postComment(@RequestBody @Valid CommentsDTO commentsDTO){
        evaluationService.postComment(commentsDTO);
        return Result.success();
    }

    /**
     * 获取评论信息
     * @param commentListDTO
     * @return
     */
    @PostMapping("/find/comment")
    public Result<PageInfo<CommentListVO>> findCommentList(@RequestBody @Valid CommentListDTO commentListDTO){
        IPage<CommentListVO> commentList = evaluationService.findCommentList(commentListDTO);
        return Result.success(PageUtils.convertToPageInfo(commentList));
    }

    /**
     * 点赞
     * @param thumbsUpDTO
     * @return
     */
    @PostMapping("/thumbs/up")
    public Result<String> thumbsUp(@RequestBody @Valid ThumbsUpDTO thumbsUpDTO){
        evaluationService.thumbsUp(thumbsUpDTO);
        return Result.success("成功");
    }













}
